package com.xxzb.pack0720;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class DemoC {
    public static void main(String[] args) throws Exception{
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入编号：");
        int empno=sc.nextInt();
        System.out.println("请输入修改后的工资：");
        double sal=sc.nextDouble();
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql:///gaofeng2207?useSSL=false";
        String username="root";
        String password="1234";
        Connection conn= DriverManager.getConnection(url,username,password);
        String sql="update gaofeng2207.emp set sal=? where empno=?";
        PreparedStatement ps=conn.prepareStatement(sql);
        //需要在执行之前给？赋值
        ps.setDouble(1,sal);//给第一个？赋值，因为工资是double类型的所以用setdouble
        ps.setInt(2,empno);//给第二个？赋值
        ps.executeUpdate();//更新操作
        //关闭
        ps.close();
        conn.close();


    }
}
